package com.stenio.fancat.controller.wx;

import com.stenio.fancat.controller.Result;
import com.stenio.fancat.exception.FanCatException;
import com.stenio.fancat.form.wx.GetFormIdForm;
import com.stenio.fancat.service.wx.GetFormIdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("addFormId")
public class GetFormIdController {

    @Autowired
    private GetFormIdService getFormIdService;

    /**
     * 获取formId
     * @param getFormIdForm
     * @return
     */
    @PostMapping("/getFormId")
    public Result<Integer> getFormId(@RequestBody GetFormIdForm getFormIdForm){
        Result<Integer> result = new Result<>();
        Integer number =null;
        try {
            number = getFormIdService.getFormId(getFormIdForm.getFormIds(),getFormIdForm.getUserId());
            result.setData(number);
        } catch (FanCatException e) {
            result.setMsg(e.getMsg());
            result.setErrorCode(e.getErrorCode());
            result.setFlag(Result.FLAG.failure);
            return result;
        }
        result.setFlag(Result.FLAG.success);
        return result;
    }

}
